﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using SmartMobile.Data;
using SMARTMobile.Models;
using SMARTMobile.Models.Local;
using SmartMobile.Data;

namespace SMARTMobile.Common
{
    public static class GlobalInformation
    {
        private static ARCUST _selectedARCUST;
        private static List<IMAGETYPE> _reportImageTypes;
        private static int _stateImageType = 0;
        private static bool _newDevice;
        private static ARSALESPTYPE _arSaleSPType;
        private static bool _loadNewData;
        private static string _connectionStringWebService;

        private static BasicHttpBinding _binding;

        //<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        private static EndpointAddress _endpoint;


        public static ARCUST SelectedARCUST
        {
            get { return _selectedARCUST; }
            set { _selectedARCUST = value; }
        }

        public static TCARCUST SelectedTCARCUS { get; set; }

        public static ARCUST UpdatingARCUST { get; set; }

        public static List<TCARCUST> DSKhachHang { get; set; }

        public static List<IMAGETYPE> ReportImageTypes
        {
            get { return _reportImageTypes; }
            set { _reportImageTypes = value; }
        }

        public static int StateImageType
        {
            get { return _stateImageType; }
            set { _stateImageType = value; }
        }

        public static bool NewDevice
        {
            get { return _newDevice; }
            set { _newDevice = value; }
        }

        public static ARSALESPTYPE ArSaleSPType
        {
            get { return _arSaleSPType; }
            set { _arSaleSPType = value; }
        }

        public static string SiteCode
        {
            get
            {
                if (ArSaleSPType != null)
                {
                    return ArSaleSPType.Sitecode;
                }

                return "123";
            }
        }

        public static bool LoadNewData
        {
            get { return _loadNewData; }
            set { _loadNewData = value; }
        }

        public static string ConnectionStringWebService
        {
            get
            {
                ////if (string.IsNullOrEmpty(_connectionStringWebService))
                ////{
                ////    _connectionStringWebService = "sskc.smartbs.vn";
                ////}

                if (ArSaleSPType != null)
                {
                    _connectionStringWebService = ArSaleSPType.Webserver;
                }

                return @"http://" + _connectionStringWebService + @"/ReloadDataSmartPhone.asmx";
            }

            set { _connectionStringWebService = value; }
        }

        public static BasicHttpBinding Binding
        {
            get
            {
                _binding = new BasicHttpBinding();
                _binding.MaxBufferSize = 2147483647;
                _binding.MaxReceivedMessageSize = 2147483647;
                _binding.SendTimeout = new TimeSpan(0, 0, 10, 0);
                _binding.ReceiveTimeout = new TimeSpan(0, 0, 10, 0);
                _binding.OpenTimeout = new TimeSpan(0, 0, 10, 0);
                _binding.CloseTimeout = new TimeSpan(0, 0, 10, 0);
                //_binding.maxArrayLength = 2147483647;
                //_binding.maxBytesPerRead = 4096;
                //_binding.maxNameTableCharCount = 16384;
                //<readerQuotas maxDepth="256" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                return _binding;
            }
            set { _binding = value; }
        }

        public static EndpointAddress Endpoint
        {
            get
            {
                if (!string.IsNullOrEmpty(GlobalInformation.ConnectionStringWebService) && GlobalInformation.ConnectionStringWebService != "http:///ReloadDataSmartPhone.asmx")
                {
                    return new EndpointAddress(GlobalInformation.ConnectionStringWebService);
                }

                return null;
            }
            set { _endpoint = value; }
        }

        public static bool IsDuyet { get; set; }
    }
}
